package dao.mybatis;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import dao.entity.UserDto;
import dao.inter.UserDao;

public class MybatisCommon {
	private SqlSessionFactory sqlSessionFactory;
	public  void query() {
		SqlSession session = null;
		try {
			session = sqlSessionFactory.openSession();
			UserDao userDao = session.getMapper(UserDao.class);
			UserDto user = new UserDto();
			user.setUsername("chenli");
			List<UserDto> users = null ;//= userDao.query(user);
			if (null != users) {
				
				System.err.println("Find " + users.size()
						+ " users named iMbatis.");
				for (UserDto u : users) {
					System.out.println(u);
				}
			}

			session.commit(true);
		} catch (Exception e) {
			// logger.error("", e);
			e.printStackTrace();
			session.rollback(true);
		} finally {
			session.close();
		}
	}

}
